package com.xpffly.assist.service.impl;

import com.xpffly.assist.service.SendEmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @Author: xpengfei
 * @Date: 2021/4/9 23:23
 * @Description：
 */
@Service
public class SendEmailServiceImpl implements SendEmailService {

    @Autowired
    private JavaMailSender mailSender;

    @Value("${mail.fromEmail.address}")
    private String fromEmailAddress;

    /**
     * 发送邮件  纯文本
     *
     * @param receiver 邮件接收人
     * @param subject  邮件主题
     * @param content  邮件内容
     */
    @Override
    public void sendTextEmail(String receiver, String subject, String content) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(fromEmailAddress);
        simpleMailMessage.setTo(receiver);
        simpleMailMessage.setSubject(subject);
        simpleMailMessage.setText(content);
        mailSender.send(simpleMailMessage);
        System.out.println("邮件发送成功...");
    }
}
